<table id="dataTable"></table>
{include file="block/layui" /}
<script type="text/html" title="状态模板" id="statusTpl">
    <input type="checkbox" name="status" value="{{ d.status }}" lay-skin="switch" lay-filter="switchStatus" lay-text="正常|关闭" {{ d.status == 1 ? 'checked' : '' }} {{ d.system == 1 ? 'disabled' : '' }} data-href="{:url('status')}?id={{ d.id }}">
</script>

<script type="text/html" title="排序模板" id="sortTpl">
    <input type="text" class="layui-input hisi-ajax-input input-sort" onkeyup="value=value.replace(/[^\d]/g,'')" value="{{ d.sort }}" data-value="{{ d.id }}" data-href="{:url('sort')}?id={{ d.id }}">
</script>

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    {{# if (d.system != 1) { }}
        <a href="{:url('edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal">修改</a><a href="{:url('del')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger hisi-tr-del">删除</a>
    {{# } else { }}
        <a href="javascript:void(0);" title="系统配置，禁止编辑" class="layui-btn layui-btn-xs layui-btn-normal layui-disabled">修改</a><a href="javascript:void(0);" title="系统配置，禁止删除" class="layui-btn layui-btn-xs layui-btn-danger layui-disabled">删除</a>
    {{# } }}
</script>

<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
        <a href="{:url('add?group='.input('param.group'))}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine">&nbsp;添加</a>
        <a data-href="{:url('status?val=1')}" class="layui-btn layui-btn-primary layui-btn-sm hisi-page-btns layui-icon layui-icon-play" data-table="dataTable">&nbsp;启用</a>
        <a data-href="{:url('status?val=0')}" class="layui-btn layui-btn-primary layui-btn-sm hisi-page-btns layui-icon layui-icon-pause" data-table="dataTable">&nbsp;禁用</a>
        <a data-href="{:url('del')}" class="layui-btn layui-btn-primary layui-btn-sm hisi-page-btns confirm layui-icon layui-icon-close red">&nbsp;删除</a>
    </div>
</script>

<script type="text/javascript">
    layui.use(['table', 'jquery', 'layer'], function() {
        var table = layui.table, formType = {:json_encode(form_type())}, 
            $ = layui.jquery, layer = layui.layer;
        table.render({
            elem: '#dataTable'
            ,url: '{:url('?group='.input('param.group'))}' //数据接口
            ,page: true //开启分页
            ,limit: 20
            ,skin: 'row'
            ,even: true
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'name', title: '标识'}
                ,{field: 'title', title: '标题'}
                ,{field: 'type', title: '类型', width: 100}
                ,{field: 'sort', title: '排序', width: 80, templet: '#sortTpl'}
                ,{field: 'status', title: '状态', width: 100, templet: '#statusTpl'}
                ,{title: '操作', width: 120, templet: '#buttonTpl'}
            ]]
        });

        $('#hisiAddGroup').on('click', function(){
            layer.prompt({
                title: '添加分组',
            }, function(value, index, elem) {

                $.post('{:url('addGroup')}', {name: value}, function(res) {
                    if (res.code == 0) {
                        layer.msg(res.msg);
                    } else {
                        location.href = res.url;
                        layer.close(index);
                    }
                }, 'json');
            });
            $('.layui-layer-input').attr('placeholder', '别名:标题，示例：user:会员');
            return false;
        });
    });
</script>